<?php

include_once 'db.php';

class Blog extends Db {

    public $table_name = "blog";

    public function __construct() {
        parent::__construct();
    }
    public function count($params) {
        $query = 'SELECT count(*) as total FROM '.$this->table_name;//SQL query
        $data = parent::select($query);
        if (!empty($data)) return (int) $data[0]['total'];
        return $data;
    }
    public function select($params) {
        /**
         * TODO: Write your code here
         */
        $query1 = 'SELECT bl.id,bl.name as name,bl.created,au.name as auname,bl.description,bl.thumb
                  FROM blog as bl
                  INNER JOIN authors as au
                  ON bl.id_author=au.id
                  ORDER BY bl.created DESC
                  LIMIT 5 ';//SQL query
        $query='SELECT * FROM '.$this->table_name;
        if (!empty($params['offset'])) {
                    $offset = ($params['offset']-1) * PER_PAGE;
                    $query .= ' LIMIT ' . $offset . ', ' . PER_PAGE;
            } else {
                $query=$query1;
            }
        $data = parent::select($query);
        return $data;
    }
    public function get_row_by_id($id) {
        return parent::get_row_by_id($id);
        
    }
    public function insert($params) {
        /**
         * TODO: Write your code here
         */
        $query = '';//SQL query
        $data = parent::insert($query);
        return $data;
    }
    public function update($params) {
        /**
         * TODO: Write your code here
         */
        $query = '';//SQL query
        $data = parent::update($query);
        return $data;
    }
    public function delete($params) {
        /**
         * TODO: Write your code here
         */
        $query = '';//SQL query
        $data = parent::delete($query);
        return $data;
    }

}
